/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Project;
import vn.ac.c0910g.assignment.Entity.ProjectFacade;

/**
 *
 * @author BachLe
 */
public class ProjectDAO {
    ProjectFacade projectFacade = lookupProjectFacadeBean();

    public ProjectDAO(){

    }
    private ProjectFacade lookupProjectFacadeBean() {
        try {
            Context c = new InitialContext();
            return (ProjectFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/ProjectFacade!vn.ac.c0910g.assignment.Entity.ProjectFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Project> getAllProject(){
        return this.projectFacade.findAll();
    }

    public void addProject(Project p){
        projectFacade.create(p);
    }

    public void updateProject(Project p){
        projectFacade.edit(p);
    }

    public void deleteProject(Project p){
        projectFacade.remove(p);
    }

    public Project findProjectById(String Id){
        return projectFacade.find(Id);
    }
}
